package com.cater.project.service;

import java.util.List;
import java.util.UUID;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cater.common.BaseEntity;
import com.cater.common.PageResult;
import com.cater.project.dao.DemandEnterpriseDao;
import com.cater.project.entity.DemandEnterprise;
import com.cater.query.CommonQuery;
import com.cater.sys.dao.DictionarydataDao;
import com.cater.sys.entity.Dictionarydata;
import com.cater.sys.service.BaseService;

/**
 * 描述：企业招聘需求 服务实现层
 * 
 * @author yong
 * @date 2018/04/25
 */
@Service
public class DemandEnterpriseServiceImpl implements BaseService<DemandEnterprise, CommonQuery, String> {

	@Autowired
	DemandEnterpriseDao dao;
	@Autowired
	DictionarydataDao dictDao;

	@Override
	public PageResult<DemandEnterprise> findPageResult(CommonQuery query) {
		PageResult<DemandEnterprise> result = new PageResult<DemandEnterprise>();
		result.setPage(query.getPage());
		result.setPageSize(query.getRows());
		int count = dao.findCount(query);
		int first = (query.getPage() - 1) * query.getRows();
		int max = query.getRows();
		List<DemandEnterprise> list = dao.findList(query, first, max);
		Dictionarydata dictStatus = null;
		for (DemandEnterprise t : list) {
			String status = String.valueOf(t.getStatus());
			if (StringUtils.isNotEmpty(status)) {
				dictStatus = dictDao.getByTypeValue(status, "project_status");
				if(dictStatus!=null) {
					t.setDictStatus(dictStatus.getValueName());
				}
			}
		}
		result.setRows(list);
		result.setRecords(count);
		return result;
	}

	@Override
	public List<DemandEnterprise> getAll() {
		return dao.getAll();
	}

	@Override
	public List<DemandEnterprise> getAllCommon(CommonQuery query) {
		return dao.getAllCommon(query);
	}

	@Override
	public int save(DemandEnterprise t) {
		return 0;
	}

	@Override
	public String saves(DemandEnterprise t) {
		t.setId(UUID.randomUUID().toString().replaceAll("-", ""));
		BaseEntity.getCreate(t);
		dao.save(t);
		return t.getId();
	}

	@Override
	public void update(DemandEnterprise t) {
		BaseEntity.getupdate(t);
		dao.update(t);
	}

	@Override
	public void delete(String id) {
		dao.delete(id);
	}

	@Override
	public DemandEnterprise getById(String id) {
		return dao.getById(id);
	}

	public DemandEnterprise getListBytelentsId(CommonQuery query) {
		return dao.getBytelentsId(query);
	}
	
	public List<DemandEnterprise> getByCompanyId(String companyId) {
		return dao.getByCompanyId(companyId);
	}
}